package com.caine.filter.handler;

import com.caine.common.entity.R;
import com.caine.common.tool.PrintTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: CaineZhu
 * @Description: 用户验证异常处理
 * @Date: Created in 14:43 2021/1/8
 * @Modified By:
 */
@Slf4j
public class AuthAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        log.error("用户验证异常", e);
        PrintTool.printMsg(httpServletResponse, R.error("用户名或密码错误"));
    }
}
